// 课程类型
export function getCourseType(type) {
  switch (type) {
    case "1":
      return "私教课";
    case "2":
      return "团课";
    case "3":
      return "训练营";
    case "4":
      return "小班课";
    default:
      return "未知类型";
  }
}

export function getCostWay(type) {
  switch (type) {
    case "1":
      return "次卡";
    case "2":
      return "时间卡";
    default:
      return "未知";
  }
}

// 课程状态
export function getCourseStatus(status) {
  // 	1 筹备中 2 筹备完成等待中 3 筹备完成不可取消 4上课中 5已完成 6用户正常取消 7用户未签到取消 8老师取消 9门店取消
  console.log("status", status);
  switch (status) {
    case "1":
      return "筹备中";
    case "2":
      return "筹备完成等待中";
    case "3":
      return "筹备完成不可取消";
    case "4":
      return "上课中";
    case "5":
      return "已完成";
    case "6":
      return "用户正常取消";
    case "7":
      return "用户未签到取消";
    case "8":
      return "老师取消";
    case "9":
      return "门店取消";
    default:
      return "未知状态";
  }
}

// 会员等级
export function getVipLevel(level) {
  switch (level) {
    case "1":
      return "青铜会员";
    case "2":
      return "白银会员";
    case "3":
      return "黄金会员";
    case "4":
      return "白金会员";
    case "5":
      return "黑金会员";
  }
}

// 获取当前日期是周几
export function getWeekDayNumber(date = new Date()) {
  const weekDayMap = ["1", "2", "3", "4", "5", "6", "7"];
  return weekDayMap[date.getDay()];
}

/**
 * 格式化时间显示
 * @param {string} timeStr - 时间字符串
 * @returns {string} - 格式化后的时间
 */
export const formatTime = (timeStr) => {
  if (!timeStr) return "";

  // 如果已经是 HH:mm 格式，直接返回
  if (/^\d{2}:\d{2}$/.test(timeStr)) {
    return timeStr;
  }

  // 处理 YYYY-MM-DD HH:mm:ss 格式
  const match = timeStr.match(/(\d{2}:\d{2})/);
  return match ? match[1] : timeStr;
};

// 格式化日期为 YYYY-MM-DD
export const formatDate = (date) => {
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, "0");
  const day = String(date.getDate()).padStart(2, "0");
  return `${year}-${month}-${day}`;
};

// 格式化日期为 DD (日期)
export const formatDay = (date) => {
  return String(date.getDate()).padStart(2, "0");
};

// 获取星期几
export const getWeekDay = (date) => {
  const weekDayMap = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
  return weekDayMap[date.getDay()];
};

// 生成日期数组
export const generateScheduleDates = () => {
  const result = [];
  const today = new Date();

  // 今天
  result.push({
    day: "今天",
    date: formatDay(today),
    value: formatDate(today),
  });

  // 明天
  const tomorrow = new Date(today);
  tomorrow.setDate(tomorrow.getDate() + 1);
  result.push({
    day: "明天",
    date: formatDay(tomorrow),
    value: formatDate(tomorrow),
  });

  // 后天
  const afterTomorrow = new Date(today);
  afterTomorrow.setDate(afterTomorrow.getDate() + 2);
  result.push({
    day: "后天",
    date: formatDay(afterTomorrow),
    value: formatDate(afterTomorrow),
  });
  // 剩下的3天
  for (let i = 3; i < 6; i++) {
    const date = new Date(today);
    date.setDate(date.getDate() + i);

    result.push({
      day: getWeekDay(date),
      date: formatDay(date),
      value: formatDate(date),
    });
  }

  return result;
};

// 计算结束时间 (开始时间 + stayTime 分钟)，支持时分秒格式
export const getEndTime = (dateStr, timeStr, stayTime) => {
  // 检查时间格式是否包含秒
  const hasSeconds = timeStr.split(":").length > 2;

  // 创建完整的日期时间字符串
  const fullDateTime = `${dateStr} ${timeStr}`;

  // 创建Date对象
  const startDateTime = new Date(fullDateTime);

  // 增加stayTime分钟
  startDateTime.setMinutes(startDateTime.getMinutes() + stayTime);

  // 提取时间部分，包含秒 (HH:MM:SS)
  const hours = String(startDateTime.getHours()).padStart(2, "0");
  const minutes = String(startDateTime.getMinutes()).padStart(2, "0");

  // 如果原始时间包含秒，则结束时间也包含秒
  if (hasSeconds) {
    const seconds = String(startDateTime.getSeconds()).padStart(2, "0");
    return `${hours}:${minutes}:${seconds}`;
  } else {
    return `${hours}:${minutes}`;
  }
};
